package com.example.validation.pojo;

import com.example.validation.custom.TelephoneNumber;
import com.example.validation.group.user.AddValidGroup;
import com.example.validation.group.user.EditValidGroup;
import jakarta.validation.constraints.*;
import lombok.Builder;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import java.io.Serializable;

@Data
@Builder
public class UserParam implements Serializable {
    private static final long serialVersionUID = 1L;

    // 设置在编辑user分组中才有的校验
    @NotEmpty(message = "userId could not be empty",groups = {EditValidGroup.class})
    private String userId;


    @NotEmpty(message = "could not be empty")
    @Email(message = "invalid email")
    private String email;

    @NotEmpty(message = "could not be empty")
    @Pattern(regexp = "^(\\d{6})(\\d{4})(\\d{2})(\\d{2})(\\d{3})([0-9]|X)$", message = "invalid ID")
    private String cardNo;

    @NotEmpty(message = "could not be empty")
    @Length(min = 1, max = 10, message = "nick name should be 1-10")
    private String nickName;

    @NotNull(message = "could not be empty")
    @Range(min = 0, max = 1, message = "sex should be 0-1")
    private int sex;

    @Max(value = 100, message = "Please input valid age")
    private int age;

    @TelephoneNumber(message = "invalid tel phone",groups = AddValidGroup.class) // 注解用在这里
    private String telPhoneNum;

}
